var backbone = require('backbone')
var utils = require('./utils');

//Model User Coté Client 
exports.User = backbone.Model.extend({

    idAttribute: "_id",

     defaults: {
        _id         : null,
        username    : "",
        mail        : "",
        password       : "",
        confirmpassword: ""
    },

    initialize: function User(){
        console.log("User Constructor coté Server");
        //On bind d'éventuelles Erreurs
        this.bind("error", function(model, error){
             console.log(error);
        })
    },

                             /********************************   Validation *********************************/
    validation: {
        username : [{
            required: true,
            msg: "Pseudo obligatoire"
        },{
            minLength: 5,
            msg: "5 caractères minimum"
        },{
            pattern : utils.nomproprePattern,
            msg: "contient des caractères interdit"
        }],
        mail: [{
          required: true,
          msg: 'Adresse Mail obligatoire'
        },{
          pattern: "email",
          msg: 'Adresse mail invalide'
        }],
        password: [{
          required: true,
          msg: 'Password obligatoire'
        },{
          pattern: utils.nomproprePattern,
          msg: 'contient des caractères interdit'
        }],
        confirmpassword: [{
          required: true,
          msg: 'Confirmation de Password obligatoire'
        },{
          equalTo: 'password',
          msg: 'Les 2 logins ne correspondent pas'
        }]
    },

                             /********************************   Getter et Setter *********************************/
    getUsername : function() {
        return this.get('username');
    },
    setUsername : function(value) {
        this.set({ username : value });
    },

    getMail : function() {
        return this.get('mail');
    },
    setMail : function(value) {
        this.set({ mail : value });
    },

    getPassword : function() {
        return this.get('password');
    },
    setPassword : function(value) {
        this.set({ password : value });
    },

    getConfirmPassword : function() {
        return this.get('confirmpassword');
    },
    setConfirmPassword : function(value) {
        this.set({ confirmpassword : value });
    }
});